<?php
    include 'template/header.html';
require_once 'lib/function.php';
    $action = isset($_GET['action'])?$_GET['action']:'list';
    $date = date("YmdHis");
    $year = substr($date,0,4);
    $month = substr($date,4,2);
    $day = substr($date,6,2);
    $hour = substr($date,8,2);
    $min = substr($date,10,2);
    $second = substr($date,12,2);
    $birthArr = birthAlert();
    $careArr = careAlert();
    $noticeArr = noticeAlert();
    $relationArr = relationAlter();
    // var_dump($birthArr);

    include 'template/main_panel.html';




    function birthAlert(){
        $sql = "SELECT
customer.c_birthday,
customer.c_name,
customer.c_tel,
customertype.ctype_info
FROM
customer
INNER JOIN customertype ON customertype.ctype_id = customer.ctype_id
where DAYOFYEAR(customer.c_birthday)-DAYOFYEAR(CURDATE())>0
ORDER BY DAYOFYEAR(YEAR(CURDATE())+substring(customer.c_birthday,6))-DAYOFYEAR(CURDATE()) desc
limit 10;";
        $rows = getAllData($sql);
        if($rows){
            return $rows;
        }
    }
    function careAlert(){
        $sql = "select c.c_name,cc.ccare_theme,cc.ccare_nexttime
from customer as c join customercare as cc on c.c_id=cc.c_id
where UNIX_TIMESTAMP(cc.ccare_nexttime)>UNIX_TIMESTAMP(NOW())
order by UNIX_TIMESTAMP(cc.ccare_nexttime) limit 0,4";
        $rows = getAllData($sql);
        if($rows){
            return $rows;
        }
    }
    function noticeAlert(){
        $sql="select n.n_theme,n.n_content,n.n_time,a.admin_name
    from notice as n join adminlogin as a on a.admin_id=n.admin_id
    order by UNIX_TIMESTAMP(n.n_time) desc limit 0,6";
    $rows = getAllData($sql);
        if($rows){
            return $rows;
        }
    }
    function relationAlter(){
        $sql = "select r.r_contheme,r.r_contype,r.r_nextcontime,c.c_name
    from relationship as r join customer as c on c.c_id=r.c_id
    where UNIX_TIMESTAMP(r.r_nextcontime)>UNIX_TIMESTAMP(NOW())
    order by UNIX_TIMESTAMP(r.r_nextcontime) limit 0,6";
    $rows = getAllData($sql);
        if($rows){
            return $rows;
        }

    }
    include 'template/foot.html';